package com.olive.config.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.olive.service.LoginService;

@RestController
public class LoginController {

    /**
     * 令牌
     */
    public static final String TOKEN = "token";
    
    @Autowired
    private LoginService loginService;
    
    /**
     * 登录方法
     * 
     * @param loginBody 登录信息
     * @return 结果
     */
    @PostMapping("/login")
    public Map<String, Object> login(@RequestBody LoginBody loginBody)
    {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("msg", "success");
        // 生成令牌
        String token = loginService.login(loginBody.getUsername(), 
        		loginBody.getPassword(), 
        		loginBody.getCode(),
                loginBody.getUuid());
        result.put(TOKEN, token);
        return result;
    }
    
    @PostMapping("/getUser")
    public Map<String, Object> getUser()
    {
	   Map<String, Object> result = new HashMap<>();
       result.put("code", 200);
       result.put("msg", "success");
       return result;
    }
}
